import { uuid } from '@/utils'
import { queryParamList as _queryParamList } from '@/api/modules/remoteMonitoring'

export interface Param {
  id: string
  measuringPointNumber: string
  indicatorName: string
}
export function useParamList() {
  const [loading, setLoading] = useState(false)
  const [lists, setLists] = useShallowState<Param[]>([])

  async function queryParamList(energyCode: string) {
    setLoading(true)
    try {
      const { data = {} } = await _queryParamList(energyCode)
      setLists(
        Object.keys(data).map(v => ({
          id: uuid(),
          measuringPointNumber: v,
          indicatorName: data[v],
        })),
      )
    }
    finally {
      setLoading(false)
    }
  }

  return {
    loading,
    lists,
    queryParamList,
  }
}
